﻿#ifndef DEFINE_H
#define DEFINE_H

#include <QObject>
#include <QString>
#include <QMap>
#include <QDebug>
#include <QTimer>

#define MOTOR_FLAG_ON      QString("border: 1px solid rgb(0, 170, 255);   border-radius: 5px; background-color: rgb(170, 255, 255);")
#define MOTOR_FLAG_OFF     QString("border: 1px solid rgb(0, 170, 255);   border-radius: 5px; background-color: rgba(170, 255, 255, 20);")
#define MOTOR_FLAG_ERR_ON  QString("border: 1px solid rgb(255, 0, 0); border-radius: 5px; background-color: rgb(255, 110, 110);")
#define MOTOR_FLAG_ERR_OFF QString("border: 1px solid rgb(255, 0, 0); border-radius: 5px; background-color: rgba(255, 110, 110, 20);")

typedef enum
{
    MODBUS_REG_GET_SYSTEM,       // 系统寄存器
    MODBUS_REG_GET_MOTOR_CTRL_M, // 主轴手动控制寄存器
    MODBUS_REG_GET_MOTOR_CTRL_S, // 副轴手动控制寄存器
    MODBUS_REG_GET_APP,          // 应用寄存器
    MODBUS_REG_GET_MOTOR_DATA,   // 电机实时数据
    MODBUS_REG_GET_ALOG_DATA,    // 算法实时数据
    MODBUS_REG_GET_CMD,          // 获取cmd数据
    MODBUS_REG_GET_DNA,          // 获取dna数据

    MODBUS_REG_GET_SYSTEM_TIME,  // 获取系统时间
    MODBUS_REG_SET_SYSTEM_TIME,  // 设置系统时间
    MODBUS_REG_SET_DEV_REBOOT,   // 设备重启
    MODBUS_REG_SET_DEV_RESET,    // 设备重置

    MODBUS_REG_SET_MADDR,        // 修改modbus地址
    MODBUS_REG_SET_LOG_LEVEL,    // 修改设备调试等级
    MODBUS_REG_SET_BAUDRATE,     // 修改设备波特率

    MODBUS_REG_FEEDBACK,    // 默认反馈修改寄存器
    MODBUS_REG_NO_FEEDBACK, // 无反馈修改寄存器
} ModbusRegCmd_e;

typedef struct
{
    ModbusRegCmd_e cmd;
    int regAddr;
    quint16 regNum;
} ModbusRegMap_s;

typedef struct
{
    quint16     maddr;
    quint16     baud;
    quint16     logLevel;
    quint16     regReboot;
    quint16     regReset;
    char        timestamp[32];
    quint64     uid;
    char        hVer[16];
    char        sVer[16];
    char        swbTiem[32];
    char        bootVer[16];
} systemReg_s;

typedef struct
{
    quint16     manual;
    quint16     posRun;
    quint16     stop;
    quint16     errReset;
    quint16     forward;
    quint16     reverse;
    quint16     zero;
    float       curSpeed;
    float       curTrip;
    quint16     posReset;
    int         powerMax;
    int         pos;
} motorCtrlReg_s;

typedef struct
{
    quint16     clusterDbg;
    quint16     motorDbg;
    quint16     motorLog_m;
    quint16     motorLog_s;
    quint16     stop;
    char        sVer_m[16];
    char        hVer_m[16];
    char        sVer_s[16];
    char        hVer_s[16];
    quint16     saveNVM;

    quint16     busy;
    quint16     mode;
    quint16     state;
    quint16     auto_switch_enable;
    quint16     errReset;
    quint16     warnClean;
    quint16     emgStop;
    quint16     engineer_authority;
    quint16     simulate_reflected_to_safety_zone;
    quint16     in_calibration_queue;
    quint16     disable_backup_point_corrdinate_limit;
    quint16     simulate_zero_point_correction_ready;
    quint16     simulate_check_limit_pos_ready;
    quint16     simulate_back_horizontal_ready;
    quint16     simulate_emergency_placement;
    quint16     code_multiplier_val_enable;
    float       codeVal;
    quint16     enable_incident_light_dead_zone;
    quint16     disable_backup_point_distance_requirements;
    quint16     enable_advance_travel;
    quint16     angle_travel_advance_1min;
    quint16     enable_gravity_compensation;
    quint16     enable_correction_compensation;
    quint16     powerEnable;
    qint16      powMax_m;
    qint16      powMax_s;
} appReg_s;

typedef struct
{
    float       curTrip;
    float       curSpeed;
    float       curEi;
    float       curPower;
    quint16     curMode;
    quint16     state;
    int         inputVal;
    quint16     errCode;
    int         switchPos;
    quint16     flagAuto;
    quint16     flagEnable;
    quint16     flagFault;
    quint16     flagRun;
    quint16     flagFinish;
    quint16     flagLimitUp;
    quint16     flagLimitDown;
    float       voltage;
    float       hallCode;
    int         code;
    int         pos;
} motorDataReg_s;

typedef struct
{
    float       x;
    float       y;
    float       z;
    float       normalHeight;
    float       normalAzimuth;
    float       rotateMain;
    float       rotateSub;
    float       tripMain;
    float       tripSub;
    float       sunHeight;
    float       sunHor;
    quint16     execState;
    quint16     finishState;
    int         errCode;

    quint16     curMode;
    quint16     curOrder;
    quint16     curAttitude;
    quint16     preMode;
    quint16     preOrder;
    quint16     preAttitude;

    float       backRotateMain;
    float       backRotateSub;
    float       backAzimuth;
    float       backHigh;
    float       backX;
    float       backY;
    float       backZ;
} alogDataReg_s;

typedef struct
{
    quint16 cmd;
    float x;
    float y;
    float z;
} cmdReg_s;

typedef struct
{
    quint16  fieldId;    // 镜场标识id
    quint16  row;        // 行
    quint16  col;        // 列
    quint16  sector;     // 区
    quint16  hcdi;       // 组
    quint16  switchId;   // 段
    quint16  line;       // 链
    quint16  lineId;     // 号

    float    m01;        // 主推杆完主推杆完全缩回时，主轴耳轴与主推杆末端的长度
    float    m02;        // 副推杆完副推杆完全缩回时，副轴耳轴与副推杆末端的长度
    float    m03;        // 主推杆耳主推杆耳轴到主轴的水平距离
    float    m04;        // 主推杆耳主推杆耳轴到主轴的垂直距离
    float    m05;        // 主轴万向主轴万向节点到主轴的水平距离
    float    m06;        // 主轴万向主轴万向节点到主轴的垂直距离
    float    m07;        // 副推杆耳副推杆耳轴到副轴的水平距离
    float    m08;        // 副推杆耳副推杆耳轴到副轴的垂直距离
    float    m09;        // 副轴到副副轴到副推杆末端的水平距离
    float    m10;        // 副轴到副副轴到副推杆末端的垂直距离
    float    m11;        // 主轴相对主轴相对于立柱端板的仰角
    float    m12;        // 主轴相对主轴相对于立柱端板的方位角
    float    m13;        // 副轴与反副轴与反射面的非正交角，即副轴与镜面的夹角
    float    m14;        // 主轴与副主轴与副轴的非正交角，即主轴与副轴在水平面上的投影交角与90°之差
    float    m21;        // 立柱安装立柱安装倾角矢量仰角
    float    m22;        // 立柱安装立柱安装倾角矢量方位角
    float    m23;        // 法兰方位法兰方位角旋转
    float    m24;        // 立柱镜场立柱镜场位置的x坐标
    float    m25;        // 立柱镜场立柱镜场位置的y坐标
    float    m26;        // 立柱镜场立柱镜场位置的z坐标

    float    longitude;  // 经度  经度
    float    latitude;   // 纬度  纬度
    float    altitude;   // 海拔高度海拔高度

    quint16  typePr;     // 主推杆类型
    quint16  typeSc;     // 副推杆类型
    float    weight;     // 定日镜重量
    float    temprature; // 组装时温度
    float    pitchPr;    // 主轴推杆螺距
    float    pitchSc;    // 副轴推杆螺距
    float    rationPr;   // 主推杆减速比
    float    rationSc;   // 副推杆减速比
    quint16  pulsesPr;   // 主轴电机极对数
    quint16  pulsesSc;   // 副轴电机极对数
    int      tripPr;     // 回平姿态主轴推杆行程
    int      tripSc;     // 回平姿态副轴推杆行程
    float    curvature;  // 镜面曲率
} dnaReg_s;

typedef struct
{
    systemReg_s        system;
    motorCtrlReg_s     motorCtrl[2];
    appReg_s           app;
    motorDataReg_s     motorData[2];
    alogDataReg_s      alogData;
    cmdReg_s           cmd;
    dnaReg_s           dna;
} localInfo_s;

extern ModbusRegMap_s           g_regMap[];
extern QString                  g_dhcp[];
extern QString                  g_baudrate[];
extern QString                  g_logLevel[];
extern QString                  g_upgradeState[];
extern QMap<quint16, QString>   g_finishState;
extern QMap<quint16, QString>   g_curMode;
extern QMap<quint16, QString>   g_cmdMode;
extern QMap<quint16, QString>   g_cmdOrder;
extern QMap<quint16, QString>   g_cmdAttitude;


#endif // DEFINE_H
